package mr

//
// RPC definitions.
//
// remember to capitalize all names.
//

import (
	"os"
	"time"
)
import "strconv"

//
// example to show how to declare the arguments
// and reply for an RPC.
//

// TIME_LIMIT ms, time coordinator wait for worker
const TIME_LIMIT = 10 * time.Second

// WAIT_TIME time work wait for next operation
const WAIT_TIME = 30 * time.Minute

type ExampleArgs struct {
	X int
}

type ExampleReply struct {
	Y int
}

type RequestArgs struct {
}

const (
	RES_INFO = iota
	RES_TASK
	RES_CMD
)

type WorkerRes struct {
	WorkerId int32
	Info     string
	Content  []string
}

type InitInfoBody struct {
	WorkerId int
	NReduce  int
}

type ResponseBody struct {
	// connected, Task, cmd
	Type_id int
	Desc    string
	Content string
}

type Interface interface {
	Len() int
	Less(i, j int) bool // i, j 是元素的索引
	Swap(i, j int)
}

type ReduceKVs struct {
	key    string
	values []string
}

type ReduceKVSlice []ReduceKVs

func (rs ReduceKVSlice) Len() int {
	return len(rs)
}

func (rs ReduceKVSlice) Less(i, j int) bool {
	return rs[i].key < rs[j].key
}

func (rs ReduceKVSlice) Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}

// Add your RPC definitions here.

// Cook up a unique-ish UNIX-domain socket name
// in /var/tmp, for the coordinator.
// Can't use the current directory since
// Athena AFS doesn't support UNIX-domain sockets.
func coordinatorSock() string {
	s := "/var/tmp/824-mr-"
	s += strconv.Itoa(os.Getuid())
	return s
}
